#coding=utf-8
import json,re
def dealdata(str):
    pattern = "(\d{4}-\d{1,2}-\d{1,2} \d{1,2}:\d{1,2}:\d{1,2})"
    res = re.split(pattern,str)
    datelist = []
    caselist = []
    casedict = {}
    alllist = []
    for key,i in  enumerate(res):
        if i =="":
            continue;
        elif re.match(pattern,i):
            datelist.append(i)
        elif "本次共运行" in i:
            alllist.append(i)
        else:
            caselist.append(i)

    #对ceselist 再进行下一轮处理
    for key,i in enumerate(caselist):
        data = i.split(":")
        detail = casedict[key]={}
        detail["description"]=data[1].replace("测试结果为","")
        detail["result"]=data[2]

    return datelist,casedict,alllist

def dealhistorydata(data):
    pattern = "(\d{4}-\d{1,2}-\d{1,2} \d{1,2}:\d{1,2}:\d{1,2})"
    res = re.split(pattern, data)
    histime = []
    hisres = []
    for (key, i) in enumerate(res):
        if "本次共运行" in i:
            i = i.replace("\n", "")
            i = i.replace("-", "")
            hisres.append(i)
            histime.append(res[key - 1])
            # detail = hisres[key] = {}
            # detail["runtime"] = res[key - 1]
            # detail["description"] = i
        else:
            continue
    hisresdict = {}
    # 将分割后的hisres 和 histime数据进一步组合成字典返回
    for (key, i) in enumerate(hisres):
        detail = hisresdict[key] = {}
        detail["runtime"] = histime[key]
        detail["description"] = hisres[key]
    return hisresdict

